<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>废弃物数据管理系统</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    <!-- 自定义CSS -->
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
</head>
<body>
    <!-- 移动退出按钮到顶部 -->
    <a href="/logout" class="logout-btn">
        <i class="fas fa-sign-out-alt"></i>
        退出登录
    </a>

    <div class="container mt-5">
        <!-- 移除原header-container，直接使用标题 -->
        <h2 class="main-title">废弃物数据管理系统</h2>
        
        <!-- 功能按钮 -->
        <div class="function-buttons">
            <button class="function-button" data-target="#image-upload">图像识别</button>
            <button class="function-button" data-target="#similar-search">相似搜索</button>
            <button class="function-button" data-target="#text-search">文字检索</button>
            <button class="function-button" data-target="#quiz">知识测试</button>
            <button class="function-button" data-target="#history">历史记录</button>
            <button class="function-button" data-target="#ai-chat">智能交流</button>
            <button class="function-button" data-target="#image-understanding">图像理解</button>
        </div>

        <!-- 内容区域 -->
        <div class="tab-content" id="myTabContent">
            <!-- 智能问答部分 -->
            <div class="tab-pane fade" id="ai-chat" role="tabpanel">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">智能问答</h5>
                        <!-- 聊天消息显示区域 -->
                        <div class="chat-messages" id="chatMessages"></div>
                        <!-- 底部区域容器 -->
                        <div class="chat-bottom-section">
                            <!-- 聊天输入区域 -->
                            <div class="chat-input-container">
                                <input type="text" id="chatInput" placeholder="请输入您的问题...">
                                <button class="send-button" onclick="ChatModule.sendMessage()">
                                    <i class="fas fa-paper-plane"></i>
                                </button>
                            </div>
                            <!-- 常见问题提示词 -->
                            <div class="search-suggestions mt-3">
                                <div class="search-tips">常见问题：</div>
                                <div class="chat-suggestions">
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">垃圾分类的四大类别是什么？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">可回收物包括哪些物品？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">厨余垃圾应该如何处理？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">过期食品属于厨余垃圾还是其他垃圾？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">郑州市的垃圾分类规则？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">塑料袋属于什么垃圾？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">废弃口罩如何处理？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">大件垃圾（如家具、电器）应该如何处理？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">垃圾分类不正确会有什么后果？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">垃圾分类的意义是什么？</span>
                                    <span class="chat-suggestion" onclick="ChatModule.insertQuestion(this)">为什么需要将厨余垃圾与其他垃圾分开处理？</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 图片上传部分 -->
            <div class="tab-pane fade" id="image-upload" role="tabpanel">
                <div class="row justify-content-center">
                    <!-- 左侧上传区域 -->
                    <div class="col-md-6">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">上传图片</h5>
                                <form id="uploadForm" class="mb-3">
                                    <div class="form-group">
                                        <input type="file" class="form-control" id="imageInput" accept="image/*" required>
                                        <label for="imageInput">
                                            <i class="fas fa-cloud-upload-alt"></i> 选择图片
                                        </label>
                                        <div class="file-name-display" id="fileNameDisplay">未选择文件</div>
                                    </div>
                                    <div class="mt-3 mb-3" style="height: 300px; display: flex; align-items: center; justify-content: center; overflow: hidden;">
                                        <img id="imagePreview" style="max-width: 100%; max-height: 300px; width: auto; height: auto; object-fit: contain; display: none;" class="img-fluid">
                                    </div>
                                    <button type="submit" class="btn btn-primary btn-lg btn-block">
                                        <i class="fas fa-search"></i> 开始识别
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 右侧识别结果区域 -->
                    <div class="col-md-6">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">识别结果与分类说明</h5>
                                <div style="background-color: #fce4ec; padding: 15px; border-radius: 8px;">
                                    <div id="predictionResult" style="display: none;">
                                        <div class="result-item" style="background: none;">
                                            <p><strong>主类别：</strong><span id="mainClass"></span></p>
                                            <p><strong>详细类别：</strong><span id="detailedClass"></span></p>
                                            <p><strong>置信度：</strong><span id="confidence"></span>%</p>
                                        </div>
                                    </div>
                                    
                                    <div id="classificationRules" style="display: none;">
                                        <h5>分类说明：</h5>
                                        <p id="categoryDefinition"></p>
                                        <h5>处理规则：</h5>
                                        <p id="disposalRules"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 相似图片结果区域 -->
                <div id="similarResults" class="mt-4" style="display: none;">
                    <!-- 相似图片的内容保持不变 -->
                </div>
                
                <!-- 历史记录中的相似图片，独立的卡片 -->
                <div class="row">
                    <div class="col-12">
                        <div class="card" id="similarHistorySection" style="display: none;">
                            <div class="card-body">
                                <h5 class="card-title">历史记录中的相似图片</h5>
                                <div id="similarHistoryImages" class="row">
                                    <!-- 相似图片将在这里动态显示 -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 相似图片搜索 -->
            <div class="tab-pane fade" id="similar-search" role="tabpanel">
                <div class="row justify-content-center">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="card-title mb-0">相似图片搜索</h5>
                            </div>
                            <div class="card-body">
                                <!-- 加载动画 -->
                                <div class="loading-overlay" id="loadingOverlay">
                                    <div class="loading-content">
                                        <div class="loading-spinner"></div>
                                        <p class="loading-text">图片相似搜索中...</p>
                                    </div>
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-12 mb-4">
                                        <form id="similarSearchForm" enctype="multipart/form-data">
                                            <div class="mb-3">
                                                <input type="file" class="form-control" id="similarImageUpload" name="file" accept="image/*">
                                                <label for="similarImageUpload">
                                                    <i class="fas fa-cloud-upload-alt"></i> 选择图片
                                                </label>
                                                <div class="file-name-display" id="similarFileNameDisplay">未选择文件</div>
                                            </div>
                                            <button type="submit" class="btn btn-primary btn-lg btn-block">
                                                <i class="fas fa-search"></i> 搜索相似图片
                                            </button>
                                        </form>
                                    </div>
                                </div>
                                <!-- 相似图片结果展示区域 -->
                                <div id="similarUploadResult" class="mb-4 text-center" style="display: none;"></div>
                                <div id="similarSearchResults" style="display: none;">
                                    <div id="similarImagesContainer" class="row">
                                        <!-- 相似图片将在这里动态显示 -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 文字搜索选项卡 -->
            <div class="tab-pane fade" id="text-search" role="tabpanel">
                <div class="row justify-content-center">
                    <div class="col-12">
                        <div class="text-search-container">
                            <div class="input-group">
                                <input type="text" id="searchQuery" class="form-control" placeholder="输入垃圾名称或类别...">
                                <div class="input-group-append">
                                    <button class="btn btn-primary" onclick="SearchModule.performTextSearch(document.getElementById('searchQuery').value)">
                                        <i class="fas fa-search mr-2"></i> 搜索
                                    </button>
                                </div>
                            </div>
                            <div id="searchResults" class="search-results-grid mt-4"></div>
                            <div id="searchSuggestions" class="search-suggestions">
                                <div class="search-tips">热门搜索：</div>
                                <div id="suggestionTags" class="d-flex flex-wrap">
                                    <!-- 搜索提示词将在这里动态显示 -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 知识问答选项卡 -->
            <div class="tab-pane fade" id="quiz" role="tabpanel">
                <div class="quiz-container">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">垃圾分类知识问答</h5>
                            <p class="card-text">测试你的垃圾分类知识！共10道题，每题10分，满分100分。</p>
                            <button id="startQuiz" class="btn btn-primary">开始答题</button>
                            <div id="quizContainer" style="display: none;" class="mt-4"></div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 历史记录选项卡 -->
            <div class="tab-pane fade" id="history" role="tabpanel">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">历史识别记录</h5>
                    </div>
                    <div class="card-body">
                        <div id="historyContainer" class="row">
                            <!-- 历史记录将在这里动态加载 -->
                            <template id="historyItemTemplate">
                                <div class="history-item">
                                    <button class="delete-btn" onclick="deleteHistory(this.getAttribute('data-filename'))">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                    <div class="row">
                                        <div class="col-md-4">
                                            <img src="" alt="历史记录图片" class="img-fluid rounded">
                                        </div>
                                        <div class="col-md-8">
                                            <h5 class="prediction-result"></h5>
                                            <p class="prediction-confidence"></p>
                                            <p class="prediction-time"></p>
                                        </div>
                                    </div>
                                </div>
                            </template>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 图片理解部分 -->
            <div class="tab-pane fade" id="image-understanding" role="tabpanel">
                <div class="row justify-content-center">
                    <!-- 左侧上传区域 -->
                    <div class="col-md-6">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">上传图片</h5>
                                <form id="imageUnderstandingForm" class="mb-3">
                                    <div class="form-group">
                                        <input type="file" class="form-control" id="understandingImageInput" accept="image/*" required>
                                        <label for="understandingImageInput">
                                            <i class="fas fa-cloud-upload-alt"></i> 选择图片
                                        </label>
                                        <div class="file-name-display" id="understandingFileNameDisplay">未选择文件</div>
                                    </div>
                                    <div class="mt-3 mb-3" style="height: 300px; display: flex; align-items: center; justify-content: center; overflow: hidden;">
                                        <img id="understandingImagePreview" style="max-width: 100%; max-height: 300px; width: auto; height: auto; object-fit: contain; display: none;" class="img-fluid">
                                    </div>
                                    <button type="submit" class="btn btn-primary btn-lg btn-block">
                                        <i class="fas fa-brain"></i> 开始分析
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 右侧理解结果区域 -->
                    <div class="col-md-6">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">图片理解结果</h5>
                                <div id="understandingResult" style="background-color: #fce4ec; padding: 15px; border-radius: 8px; display: none;">
                                    <div id="firstAnswer" class="mb-4" style="white-space: pre-line;"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 后续问答区域 -->
                <div id="followUpSection" class="row justify-content-center mt-4" style="display: none;">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">图片后续理解</h5>
                                <div class="chat-input-container">
                                    <div class="input-group">
                                        <input type="text" id="followUpQuestion" class="form-control" placeholder="请输入您对图片的问题...">
                                        <div class="input-group-append">
                                            <button class="btn btn-primary" onclick="ImageUnderstandingModule.sendFollowUpQuestion()">
                                                <i class="fas fa-paper-plane"></i> 发送问题
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div id="followUpAnswer" class="mt-4" style="white-space: pre-line; background-color: #fce4ec; padding: 15px; border-radius: 8px;"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap 依赖 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
    <!-- 自定义JavaScript -->
    <script src="{{ url_for('static', filename='js/main.js') }}"></script>
</body>
</html>